﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADA.Entity;
using ADA.Business;

namespace ADA.Presentation.PRL.Account
{
    public partial class AddAdminAccForm : Form
    {
        bool flag;
        MainForm main;

        public AddAdminAccForm(MainForm Main)
        {
            main = Main;
            InitializeComponent();
        }

        private void AddAdminAccForm_Load(object sender, EventArgs e)
        {
            lblError.Text = "";
            tbxLoginName.Select();
        }

        private void validate()
        {
            flag = true;
            if (tbxPhone.Text.Trim().Equals("") == true)
            {
                errorPhone.SetError(tbxPhone, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorPhone.Clear();
            }
            if (tbxEmail.Text.Trim().Equals("") == true)
            {
                errorEmail.SetError(tbxEmail, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorEmail.Clear();
            }
            if (tbxConfirmPassword.Text.Trim().Equals(tbxPassword.Text.Trim()) == false)
            {
                errorConfirmPass.SetError(tbxConfirmPassword, Common.MESSAGE_ERROR_CONFIRM_PASSWORD_INCORECT);
                flag = false;
            }
            else
            {
                errorConfirmPass.Clear();
            }
            if (tbxPassword.Text.Trim().Equals("") == true)
            {
                errorPass.SetError(tbxPassword, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorPass.Clear();
            }
            if (tbxLoginName.Text.Trim().Equals("") == true)
            {
                errorName.SetError(tbxLoginName, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorName.Clear();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            validate();
            if (flag == false)
            {
                return;
            }
            BOLAccount bolAcc = new BOLAccount();
            Admin ad = new Admin();
            string message;
            ad.Name = tbxLoginName.Text.Trim();
            ad.Password = tbxPassword.Text.Trim();
            ad.Email = tbxEmail.Text.Trim();
            ad.Phone = tbxPhone.Text.Trim();
            if (bolAcc.addAdmin(ad, out message) == true)
            {
                main.LoadTabPage_AdminAccount();
                this.Close();
            }
            else
            {
                lblError.Text = message;
            }
        }
    }
}
